/**
 * Created by Ford Zhang on 2017/1/5.
 */

function positionMessage() {
	if(!document.getElementById) return false;
	if(!document.getElementById('message')) return false;

	var element = document.getElementById('message');
	element.style.position = 'absolute';
	element.style.left = '50px';
	element.style.top = '100px';

	movement = setTimeout('moveMessage()', 10);
}

function moveMessage() {
	if(!document.getElementById) return false;
	if(!document.getElementById('message')) return false;

	var element = document.getElementById('message');
	var xPos = parseInt(element.style.left);	//parseInt 用来取得字符串中的整数部分，这样得到的是节点的纵坐标
	var yPos = parseInt(element.style.top);

	if(xPos == 200 && yPos == 300) {
		return true;
	}

	if(xPos <200 ) {
		xPos++;
	}

	if(xPos > 200) {
		xPos--;
	}

	if (yPos < 300) {
		yPos++;
	}

	if (yPos > 300) {
		yPos--;
	}

	element.style.left = xPos + 'px';
	element.style.top = yPos + 'px';
	movement = setTimeout('moveMessage()', 10);
}

addLoadEvent(positionMessage);